package org.mushroomdb.client.gui;

import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import com.sun.java.swing.plaf.windows.*;

public class TableHeaderTest {
	public static void main(String[] a) throws Exception {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		JFrame f = new JFrame();
		JTable table = new JTable(5, 5);
		f.getContentPane().add(new JScrollPane(table));

		// Replace the XP renderer with our own
		JTableHeader header = table.getTableHeader();
		TableCellRenderer oldRenderer = header.getDefaultRenderer();
		String name = oldRenderer.getClass().getName();
		if (name.equals("com.sun.java.swing.plaf.windows.WindowsTableHeaderUI$XPDefaultRenderer")) {
			//header.setDefaultRenderer(new MyHeaderRenderer((DefaultTableCellRenderer) oldRenderer));
		}
		f.setBounds(100, 100, 200, 200);
		f.setVisible(true);
	}

	public static class MyHeaderRenderer extends DefaultTableCellRenderer {
		private DefaultTableCellRenderer oldRenderer;

		MyHeaderRenderer(DefaultTableCellRenderer oldRenderer) {
			this.oldRenderer = oldRenderer;
		}

		public Component getTableCellRendererComponent(JTable table,
				Object value, boolean isSelected, boolean hasFocus, int row,
				int column) {
			if (table != null) {
				JTableHeader header = table.getTableHeader();
				if (header != null) {
					setFont(header.getFont());
				}
			}
			setText((value == null) ? "" : value.toString());
			setHorizontalAlignment(JLabel.CENTER);
			return this;
		}

		public void paint(Graphics g) {
			// Make the XP renderer draw its background
			Dimension size = getSize();
			oldRenderer.setSize(size);
			oldRenderer.setOpaque(false);
			oldRenderer.paint(g);

			// Draw something nice
			g.setColor(Color.green);
			g.drawRect(5, 1, size.width - 10, size.height - 5);

			super.paint(g);
		}
	}
}
